package com.yxhl.zoume.core.func.push;

import android.content.Context;

import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;
import com.yxhl.zoume.core.func.push.model.PushMessage;
import com.yxhl.zoume.utils.LOG;

/**
 * Created by vhawk on 16/4/6.
 */
public class ZMUmengNotificationClickHandler extends UmengNotificationClickHandler {

    private static final String TAG = "ZMUMNotification";

    private static final String ID = "id";
    private static final String BIZ_TYPE = "bizType";
    private static final String ACTION = "action";

    /**
     * 通知被点击事的效果
     *
     * @param context
     * @param uMessage
     */
    @Override
    public void dealWithCustomAction(Context context, UMessage uMessage) {
        super.dealWithCustomAction(context, uMessage);

        PushMessage pushMessage = new PushMessage();
        if (uMessage.extra.containsKey(ID)) {
            pushMessage.setId(uMessage.extra.get(ID));
        }
        if (uMessage.extra.containsKey(BIZ_TYPE)) {
            pushMessage.setBizType(Integer.parseInt(uMessage.extra.get(BIZ_TYPE)));
        }
        if (uMessage.extra.containsKey(ACTION)) {
            pushMessage.setAction(uMessage.extra.get(ACTION));
        }
        PushMessageDispatcher.getInstance().onClick(context, pushMessage);
    }

    @Override
    public void launchApp(Context context, UMessage uMessage) {
        super.launchApp(context, uMessage);
        test("launchApp");
    }

    private void test(String clickAction) {
        LOG.v(TAG, clickAction);
    }

    @Override
    public void openActivity(Context context, UMessage uMessage) {
        super.openActivity(context, uMessage);
        test("openActivity");
    }

    @Override
    public void openUrl(Context context, UMessage uMessage) {
        super.openUrl(context, uMessage);
        test("openUrl");
    }
}
